#include "glob.h"

extern Am2302_TypeDef am2302_th;

int main(void)
{
    SystemInit();
    GPIOInit();

    MotorPWM_Init();
    Time0Init(SystemCoreClock / 1000000, 10);
    UartInit(UARTPORT0, 115200);
    UartInit(UARTPORT1, 9600);
    UartInit(UARTPORT2, 38400);

    UartInit(UARTPORT3, 115200);
    SPI0Init();
    SPI1Init();
    ms5611_init();
    RTCInit();
    PowerOn_SelfCheck();

    CTA_Init(&CTA);
    NVIC_Config();
    SysTick_Config(SystemCoreClock / 1000);

    CtrPWMST(ON);
    //    WDTInit();
    if (BOARAD_NUM == 1)
    {
        myDelay(2000);
        mem_WrReParaN(ERe24cY1, EDateArea, lcd_save_data, 124);
        mem_WrReParaN(ERe24cY1, ECalData1, (uint8_t *)&WorkFlow, sizeof(STR_WORKFLOW));
        mem_WrReParaN(ERe24cY1, ECalData2, (uint8_t *)&data_query_s, 16);
        PageLimit(0, data_query_s.his.max_page);
        PageLimit(1, data_query_s.log.max_page);
        for (uint8_t i = 0; i < 5; i++)
        {
            lcd_data[53 + i] = 2000 + (i * 1000);
        }
        DWIN_Pic_Set(0x0001);
        PowerUpDataInit();
    }
    else if (BOARAD_NUM == 2)
    {
        OUT3_ON;
        PID_init(pid, PID_POSITION, 1900, 3000);
        ModbusWriteCoil(0x14, 42, 0);
        mem_WrReParaN(ERe24cY1, ECalData1, (uint8_t *)&WorkFlow, sizeof(STR_WORKFLOW));
    }

    while (1)
    {
        // WDTFeed();
        GetAdcValue();
        GetActualFlow();
        WorkFlowManage();
        TimeProcess();
        Uart3MsgHandle();
        Uart2Manage();
        // DWINDgusTXD();
    }
}

/*********************************************************************************************************
  End Of File
*********************************************************************************************************/
